package no.ntnu.idi.deid.documentunits;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Jaspreet
 *
 */

public class Section extends ArrayList<Sentence> {

	private static final long serialVersionUID = 1L;
	private int id;
	private int startIndex;
	private int endIndex;
	private Document mParent;
	
	/**
	 * Constructor
	 * @param id Section ID
	 * @param sentenceList The list of sentences in the section
	 * @throws IllegalArgumentException If sentenceList isEmpty
	 */
	public Section(int id, List<Sentence> sentenceList) {
		super(sentenceList);
		if(sentenceList.isEmpty()) {
			throw new IllegalArgumentException("Failed: Trying to create an empty section");
		}
		startIndex = get(0).getIndex();
		endIndex = get(size()-1).getIndex();
		this.id = id;
		setParents();
	}
	
	private void setParents() {
		for(Sentence sentence: this) {
			sentence.setParent(this);
		}
	}
	
	public Document getDocument() {
		return mParent;
	}

	public void setParent(Document mParent) {
		this.mParent = mParent;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}
	
	public int getId(){
		return id;
	}

	public void print(){
		for(Sentence s: this){
			System.out.println(s);
		}
	}
}
